/* 
 * File:   Triangle.h
 * Author: eliana
 *
 * Created on May 19, 2012, 1:29 PM
 */

#ifndef TRIANGLE_H
#define	TRIANGLE_H

#include "Material.h"
#include "Vector4D.h"
#include "Ray.h"
#include "Object.h"

class Triangle : public Object
{
public:
    
    /**
     * Constructor
     * @param v0 Vertex 0
     * @param v1 Vertex 1
     * @param v2 Vertex 2
     * @param tex0 Texture coordinate of vertex 0
     * @param tex1 Texture coordinate of vertex 1
     * @param tex2 Texture coordinate of vertex 2
     */
    Triangle( Vector4D v0, Vector4D v1, Vector4D v2, Vector4D tex0, Vector4D tex1, Vector4D tex2 );
    
    /**
     * Destructor
     */
    virtual ~Triangle();
    
    /**
     * From Object interface:
     * Computes the intersection of the object with the given ray
     * @param ray Ray that may intersect the object
     * @param t Parameter of the ray, indicating how far from the ray origin is 
     *          the intersection
     * @return true if intersects, false otherwise
     */
    bool computeRayIntersection( Ray& ray, double& t );
    
    /**
     * From Object interface:
     * Gives the Normal vector of the object at a given point.
     * If the point is not in the object's surface, returns null vector (0,0,0,1)
     * @param point Point in the object's surface
     * @return the Normal vector of the object
     */
    Vector4D getNormal( Vector4D& point );
    
    /**
     * From Object interface:
     * Sets the id of the object's material.
     * All the materials are stored in the Scene class.
     * @param materialId Id of the material
     */
    void setMaterial( int materialId );
    
    /**
     * From Object interface:
     * @return The Id of the object's material
     */
    int getMaterialId();
    
    /**
     * From Object interface:
     * @return The type of the object
     */
    ObjectType getType();
    
    /**
     * From Object interface:
     * Gives access to the min and maximum values of the axis aligned bounding 
     * box of the object
     * @param min Minimum values of the aabb
     * @param max Maximum values of the aabb
     */
    void getBoundingBox( Vector4D& min, Vector4D& max );
    
    /**
     * Gives the coordinates of the three vertices that compose the triangle
     * @param v0 Vertex 0
     * @param v1 Vertex 1
     * @param v2 Vertex 2
     */
    void getVertices( Vector4D& v0, Vector4D& v1, Vector4D& v2 );
    
    /**
     * Gives the texture coordinates of the three vertices that compose the triangle 
     * @param tex0 Texture coordinate of vertex 0
     * @param tex1 Texture coordinate of vertex 1
     * @param tex2 Texture coordinate of vertex 2
     */
    void getTextureCoordinates( Vector4D& tex0, Vector4D& tex1, Vector4D& tex2 );
    
private:
    
    /** Id of the material */
    int _materialId;
    
    /** Vertices */
    Vector4D _v0;
    Vector4D _v1;
    Vector4D _v2;
    
    /** Texture coordinates */
    Vector4D _tex0;
    Vector4D _tex1;
    Vector4D _tex2;
};

#endif	/* TRIANGLE_H */

